<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/5
 * Time: 23:44
 */

namespace App\DesignPattern\Observer;
use App\DesignPattern\Observer;


class Event
{
    /**
     * @var array
     */
    private $observers = [];

    /**
     * 添加一个观察者
     * @param Observer $observer
     */
    public function addObserver($observer)
    {
        $this->observers[] = $observer;
    }

    public function fire()
    {
        echo '事件发生啦<br/>';
        foreach ($this->observers as $observer)
        {
            $observer->eventResponse('发生了事件，就传递点参数给你。');
        }
    }
}